package cn.asura.network;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Test1 {
    public static void main(String[] args) {
        InetAddress localHost = null;
        InetAddress remoteHost = null;
        try {
            localHost = InetAddress.getLocalHost(); // 本地主机
            remoteHost = InetAddress.getByName("www.baidu.com");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }


        System.out.println("localHost = " + localHost);
        System.out.println("百度ip地址 = " + remoteHost.getHostAddress());
        System.out.println("百度主机名 = " + remoteHost.getHostName());
    }
}
